package org.edu.modules.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.edu.modules.oa.entity.SysDictItemEntity;
import org.edu.modules.oa.entity.VeOaMeetAttenEntity;
import org.edu.modules.oa.mapper.ISysDictItemMapper;
import org.edu.modules.oa.mapper.IVeOaMeetAttenMapper;
import org.edu.modules.oa.service.IVeOaMeetAttenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class VeOaMeetAttenServiceImpl implements IVeOaMeetAttenService {
    @Resource
    private IVeOaMeetAttenMapper veOaMeetAttenMapper;
    @Resource
    private ISysDictItemMapper sysDictItemMapper;
    @Override
    public HashMap<String, Object> selectMeetAtten(Integer startPage, Integer pageSize, String attenType, Integer id) {
        HashMap<String, Object> map = new HashMap<>();
        //创建mybatisplus查询的条件
        QueryWrapper<VeOaMeetAttenEntity> wrapper = new QueryWrapper<>();
        if(null != attenType && !attenType.equals("")){
            wrapper.eq("atten_type", attenType);
        }
        wrapper.eq("meet_id", id);
        wrapper.orderByDesc("create_time");
        //创建mybatisplus的分页器
        IPage<VeOaMeetAttenEntity> page = new Page<>(startPage,pageSize);
        // 条件加上分页查询
        page = veOaMeetAttenMapper.selectPage(page,wrapper);
        //获取查询的结果
        List<VeOaMeetAttenEntity> list = page.getRecords();
        int count = veOaMeetAttenMapper.selectCount(wrapper);
        map.put("list",list);
        map.put("count",count);
        return map;
    }

    //字典-----考勤状态的下拉框
    public List<SysDictItemEntity> selectAttenType() {
        QueryWrapper<SysDictItemEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("dict_id","1384319679085441025");
        List<SysDictItemEntity> list = sysDictItemMapper.selectList(wrapper);
        return list;
    }

    //修改考勤状态
    public int updateAttenType(VeOaMeetAttenEntity veOaMeetAttenEntity) {
        return veOaMeetAttenMapper.updateById(veOaMeetAttenEntity);
    }
}
